<?php
declare (strict_types=1);

namespace app\common\model;

use ffhome\frame\model\BaseModel;

class TourEnroll extends BaseModel
{
    const MODEL_NAME = 'tour_enroll';

    /**
     * 状态:待确认
     */
    const S_UNCONFIRMED = 1;
    /**
     * 状态:已确认
     */
    const S_CONFIRMED = 2;
    /**
     * 状态:已付款
     */
    const S_PAID = 3;
    /**
     * 状态:已取消
     */
    const S_CANCELLED = 4;

    public static function computeMoney(array &$data)
    {
        $route = TourRoute::get($data['route_id']);
        if (empty($data['market_rebate_money'])) $data['market_rebate_money'] = 0;
        if (empty($data['cost_rebate_money'])) $data['cost_rebate_money'] = 0;
        $data['adult_num'] = intval($data['adult_num']);
        $data['child_num'] = intval($data['child_num']);
        $data['single_price'] = ($data['adult_num'] + $data['child_num']) % 2 == 1 ? $route['single_price'] : 0;
        $data['market_money'] = $route['adult_market_price'] * $data['adult_num']
            + $route['child_market_price'] * $data['child_num'] + $data['single_price'] + $data['market_rebate_money'];
        $data['peer_money'] = $route['adult_peer_price'] * $data['adult_num']
            + $route['child_peer_price'] * $data['child_num'] + $data['single_price'];
        $data['cost_money'] = $route['adult_cost_price'] * $data['adult_num']
            + $route['child_cost_price'] * $data['child_num'] + $data['single_price'] + $data['cost_rebate_money'];
    }
}